package com.ea.wxwork.config;

import com.ea.repository.mapper.SysConfigMapper;
import com.ea.util.RedisUtils;
import com.ea.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import java.util.Objects;

/**
 * @ClassName WxworkConfig
 * @Description TODO
 * @Author XIONG CAI
 * @Date 2024/11/12
 */
@Configuration
public class WxworkConfig {
    @Autowired
    private static RedisUtils redisUtils;
    @Autowired
    private static SysConfigMapper sysConfigMapper;

    public static String getWxworkApiDomain() {
        String key = "wxwork.api.domain";
        String appkey = Objects.isNull(redisUtils.get(key)) ? "" : redisUtils.get(key).toString();
        if (StringUtil.isBlank(appkey)) {
            appkey = sysConfigMapper.getValueByKey(key);
            redisUtils.set(key, appkey);
        }
        return appkey;
    }

    public static String getAppKey() {
        String key = "wxwork.appKey";
        String appkey = Objects.isNull(redisUtils.get(key)) ? "" : redisUtils.get(key).toString();
        if (StringUtil.isBlank(appkey)) {
            appkey = sysConfigMapper.getValueByKey(key);
            redisUtils.set(key, appkey);
        }
        return appkey;
    }


    public static String getAppSecret() {
        String key = "wxwork.appSecret";
        String appkey = Objects.isNull(redisUtils.get(key)) ? "" : redisUtils.get(key).toString();
        if (StringUtil.isBlank(appkey)) {
            appkey = sysConfigMapper.getValueByKey(key);
            redisUtils.set(key, appkey);
        }
        return appkey;
    }

    public static String getAgentId() {
        String key = "wxwork.agentId";
        String appkey = Objects.isNull(redisUtils.get(key)) ? "" : redisUtils.get(key).toString();
        if (StringUtil.isBlank(appkey)) {
            appkey = sysConfigMapper.getValueByKey(key);
            redisUtils.set(key, appkey);
        }
        return appkey;
    }

    public static String getCorpId() {
        String key = "wxwork.corpId";
        String appkey = Objects.isNull(redisUtils.get(key)) ? "" : redisUtils.get(key).toString();
        if (StringUtil.isBlank(appkey)) {
            appkey = sysConfigMapper.getValueByKey(key);
            redisUtils.set(key, appkey);
        }
        return appkey;
    }



    public static String getCorpSecret() {
        String key = "wxwork.corpSecret";
        String appkey = Objects.isNull(redisUtils.get(key)) ? "" : redisUtils.get(key).toString();
        if (StringUtil.isBlank(appkey)) {
            appkey = sysConfigMapper.getValueByKey(key);
            redisUtils.set(key, appkey);
        }
        return appkey;
    }

}
